package zt

import (
	"crypto/rand"
	"math/big"
)

// Max
// Description 获得多个int64中最大的
// author: sagit
// date: 2022/2/10 22:25
// params:
// return:
func Max(nums ...int64) int64 {
	var max int64 = 0
	for i, v := range nums {
		if i == 0 {
			max = v
		} else if v > max {
			max = v
		}
	}
	return max
}

// GenRandCountForDiff
// Description 生成指定范围内的 count 个不重复数字
// author: sagit
// date: 2022/2/10 22:28
// params:
// return:
func GenRandCountForDiff(min, max int64, count int) []int64 {
	var (
		allCount map[int64]int64
		result   []int64
	)
	allCount = make(map[int64]int64)
	maxBigInt := big.NewInt(max)
	for {
		i, _ := rand.Int(rand.Reader, maxBigInt)
		number := i.Int64()
		if i.Int64() >= min {
			_, ok := allCount[number]
			if !ok {
				result = append(result, number)
				allCount[number] = number
			}
		}
		if len(result) >= count {
			return result
		}
	}
}

// Random
// Description 在指定范围内随机生成数字
// author: sagit
// date: 2022/2/10 22:31
// params:
// return:
func Random(min, max int64) int64 {
	maxBigInt := big.NewInt(max)
	for {
		i, _ := rand.Int(rand.Reader, maxBigInt)
		if i.Int64() >= min {
			return i.Int64()
		}
	}
}
